from .center_crop import crop_data_by_coordinates, patch_generator
import numpy as np 
import os 

def get_bboxes(three_modalities_arr, seg_out):
    ## Transpose
    new_three_arr = []
    for arr in three_modalities_arr:
        new_three_arr.append(arr.transpose([1, 2, 0]))
    seg_out = seg_out.transpose([1, 2, 0])

    coordinates = patch_generator(seg_out)
    print(f"boxes coordinates is {coordinates}")
    print(f"*" * 100)
    bboxes = crop_data_by_coordinates(new_three_arr, coordinates=coordinates)

    return bboxes


def save_bboxes(three_bboxes, save_dir):

    os.makedirs(save_dir, exist_ok=True)
    np.save(os.path.join(save_dir, "t1_bbox.npz"), three_bboxes[0])
    np.save(os.path.join(save_dir, "t2_bbox.npz"), three_bboxes[1])
    np.save(os.path.join(save_dir, "adc_bbox.npz"), three_bboxes[2])

    print(f"bboxes saved successfully...")
    